/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.bzy.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.bzy.entity.BzyQjw;
import com.zcm.modules.bzy.service.BzyQjwService;

/**
 * qjwController
 * @author www
 * @version 2018-11-20
 */
@Controller
@RequestMapping(value = "${adminPath}/bzy/bzyQjw")
public class BzyQjwController extends BaseController {

	@Autowired
	private BzyQjwService bzyQjwService;
	
	@ModelAttribute
	public BzyQjw get(@RequestParam(required=false) String id) {
		BzyQjw entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bzyQjwService.get(id);
		}
		if (entity == null){
			entity = new BzyQjw();
		}
		return entity;
	}
	
	@RequiresPermissions("bzy:bzyQjw:view")
	@RequestMapping(value = {"list", ""})
	public String list(BzyQjw bzyQjw, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BzyQjw> page = bzyQjwService.findPage(new Page<BzyQjw>(request, response), bzyQjw); 
		model.addAttribute("page", page);
		return "modules/bzy/bzyQjwList";
	}

	@RequiresPermissions("bzy:bzyQjw:view")
	@RequestMapping(value = "form")
	public String form(BzyQjw bzyQjw, Model model) {
		model.addAttribute("bzyQjw", bzyQjw);
		return "modules/bzy/bzyQjwForm";
	}

	@RequiresPermissions("bzy:bzyQjw:edit")
	@RequestMapping(value = "save")
	public String save(BzyQjw bzyQjw, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bzyQjw)){
			return form(bzyQjw, model);
		}
		bzyQjwService.save(bzyQjw);
		addMessage(redirectAttributes, "保存qjw成功");
		return "redirect:"+Global.getAdminPath()+"/bzy/bzyQjw/?repage";
	}
	
	@RequiresPermissions("bzy:bzyQjw:edit")
	@RequestMapping(value = "delete")
	public String delete(BzyQjw bzyQjw, RedirectAttributes redirectAttributes) {
		bzyQjwService.delete(bzyQjw);
		addMessage(redirectAttributes, "删除qjw成功");
		return "redirect:"+Global.getAdminPath()+"/bzy/bzyQjw/?repage";
	}

}